IF OBJECT_ID('fGetFragmentOrdinal') IS NOT NULL 
BEGIN 
    DROP FUNCTION fGetFragmentOrdinal
    IF OBJECT_ID('fGetFragmentOrdinal') IS NOT NULL
        PRINT '<<< FAILED DROPPING FUNCTION fGetFragmentOrdinal >>>'
    ELSE 
        PRINT '<<< DROPPED FUNCTION fGetFragmentOrdinal >>>'
END
GO
CREATE FUNCTION dbo.fGetFragmentOrdinal
(
    @ID int = NULL
)
RETURNS tinyint
AS
BEGIN
    DECLARE @Ord tinyint

    SELECT
        @Ord = SortOrdinal
    FROM
        Fragment
    WHERE
        FragmentID = @ID

RETURN @Ord
END

GO
GRANT EXECUTE ON fGetFragmentOrdinal TO public
GO
IF OBJECT_ID('fGetFragmentOrdinal') IS NOT NULL 
    PRINT '<<< CREATED FUNCTION fGetFragmentOrdinal >>>' 
ELSE 
    PRINT '<<< FAILED CREATING FUNCTION fGetFragmentOrdinal >>>' 
GO